/******************************************************************************
 for specific details, see: http://www.pageresource.com/jscript/jwinopen.htm
 ******************************************************************************/
 function launchWindow(url,name,width,height) {
   window.open(url,name,"width="+width+",height="+height+",copyhistory=no,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
 }
 
 function launchWindowPrj(url,name,width,height) {
   window.open(url,name,"width="+width+",height="+height+",copyhistory=no,directories=no,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=no,toolbar=no");
 }
/********************************************************************************/
/* Added by Deepak for bug 655*/
 function launchWindowWithToolbar(url,name,width,height) {
   launchedWindow = window.open(url,name,"width=" + width + ",height=" + height + ",directories=no,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
   launchedWindow.focus();
 }
/********************************************************************************/
 function launchWindowWithMenubar(url,name,width,height) {
   launchedWindow = window.open(url,name,"width=" + width + ",height=" + height + ",directories=no,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=no,toolbar=no");
   launchedWindow.focus();
 }

/******************************************************************************/
 function submitAction(action) {
   document.form.action = action;
   document.form.submit();
 }
/******************************************************************************/
 function validNumberField(fieldName) {
   return (document.getElementsByName(fieldName)[0].value.length == 0)||
           document.getElementsByName(fieldName)[0].value.match(/^\s*\d+\s*$/);
 }
/******************************************************************************/
 function checkisbn(isbn) {
   if (isbn.length > 0) {
     isbn = isbn.replace(/[^0-9X]/gi,"");
	 
     if (isbn.length ==10) {
       arry = isbn.match(/./g);

       checkdigit = 11 - ((10*arry[0] +  9*arry[1] +  8*arry[2]+
                            7*arry[3] +  6*arry[4] +  5*arry[5]+
                            4*arry[6] +  3*arry[7] +  2*arry[8]) % 11);

       if ( checkdigit == 10 ) checkdigit = "X";
       if ( checkdigit == 11 ) checkdigit = 0;

       return arry[9] == checkdigit;
     }
     else if(isbn.length == 13 )
	   {
		
			 arry = isbn.match(/./g);
			 if(arry[0]==9 && arry[1]==7 && arry[2]==8){
				checkdigit =((1*arry[0] + 3*arry[1] + 1*arry[2] +3*arry[3] + 1*arry[4] + 3*arry[5] + 
							1*arry[6] + 3*arry[7] + 1*arry[8] + 3*arry[9] + 1*arry[10] + 3*arry[11])%10);
				
				if (checkdigit==0) checkdigit1=0;
				if (checkdigit==1) checkdigit1=9;
				if (checkdigit==2) checkdigit1=8;
				if (checkdigit==3) checkdigit1=7;
				if (checkdigit==4) checkdigit1=6;
				if (checkdigit==5) checkdigit1=5;
				if (checkdigit==6) checkdigit1=4;
				if (checkdigit==7) checkdigit1=3;
				if (checkdigit==8) checkdigit1=2;
				if (checkdigit==9) checkdigit1=1;
				
				return arry[12] == checkdigit1;
			}
			else
				return false;
	   }
	 else
		 return false;
   }
   else
	   return false;
 }
/******************************************************************************
 Validate the project identifier IF it is an ISBN or a BOOKCODE
 ******************************************************************************/
 function validProjectId() {
   if (document.form.projectIdType.value == 'ISBN') {
     return checkisbn(document.form.projectId.value);
   }
   else
   if (document.form.projectIdType.value == 'BOOKCODE'){
     return (document.form.projectId.value.length <= 6);
   }
   else return true;  //assumed valid if not ISBN
 }

//changed on date 18122002
function validchargedISBN() {
    var price = document.form.chargedISBN.value;
	//alert(price);
    if (price == null || price.length == 0)
     return false;
	 else
		 return true;
   }
 
/******************************************************************************
 Validate the quoted currency format
 ******************************************************************************/
 function validCurrencyField() {
    var price = document.form.quotedPrice.value;
    if (price != null && price.length > 0)
    {
        if (!(price.match(/^\s*\d*\.{0,1}\d+\s*$/)
            || price.match(/^\s*\d+\s*$/)
            || price.match(/^\s*\d+\.{0,1}\d*\s*$/)))
        {
            alert ("Quoted Price can ONLY have numeric values!");
            return false;
        }
        if (price.indexOf('.') > -1)
        {
            var S = price.split(".");
            //alert ('String 0 ' +S[0] + ':: 1 ' + S[1]);
            if ( S[1].length > 2)
            {
                alert("Quoted Price must be in the form $$$.$$");
                return false;
            } else
            if (S[0].length > 10)
            {
                alert ("Quoted Price must be less than 10 billion $/GBP!");
                return false;
            }
        }
        else if (price.length > 10)
        {
            alert("Quoted Price must be less than 10 billion $/GBP!");
            return false;
        }
    }
    return true;
 }
/******************************************************************************
 Validate the project identifier IF it is an ISBN or a BOOKCODE; submit if valid.
 ******************************************************************************/
 function validateAndSubmitAction(action) {

   if (!validProjectId  (           )) return alert(document.form.projectIdType.value + ' entered is not valid.  Please try again.');
   if (!validNumberField("copyright")) return alert('Copyright must contain only numeric digits.'                                  );
   if (!validNumberField( "edition" )) return alert(  'Edition must contain only numeric digits.'                                  );   
  /****************************************************************************/
   submitAction(action);
 }

/******************************************************************************
 changes done for bug A JavaScript alert Pop up window with appropriate error message plus another window I.e Upload pops up where it shows as if project is getting created.
 by pankaj on 27-02-2004
 Overloaded method to Validate the project identifier IF it is an ISBN or a BOOKCODE; submit if valid.
 ******************************************************************************/
 function validateAndSubmitActionOverload(action,loadingJsp) {
   if (!validProjectId  (           )) return alert(document.form.projectIdType.value + ' entered is not valid.  Please try again.');
   if (!validNumberField("copyright")) return alert('Copyright must contain only numeric digits.'                                  );
   if (!validNumberField( "edition" )) return alert(  'Edition must contain only numeric digits.'                                  );   
   loadingWindow = window.open(loadingJsp,"Loading","height=215,width=190,menubar=false,location=false,scrollbars=false,status=false");
   document.body.style.cursor='wait';
  /****************************************************************************/
   submitAction(action);
 }
 //changes end
/******************************************************************************
 Validate the quoted currency format
 ******************************************************************************/
 function validateAndSubmitUsageAction(action) {

   if (!validCurrencyField()) return;
  /****************************************************************************/
   submitAction(action);
 }
/******************************************************************************/
/*added by sameer on 04/04/2003 for SIR 757
This function open the Source details screen with the Source Code provided to it*/
function showDetails(path,code)
{
	//Start :added by Prasad on 05-16-2004 for Handling "&" in Source Name
	var newCode = code;

	for( var i = 0; i < newCode.length; i++){

		   newCode= newCode.replace(/&/,'%26');
			
	}
	var url = path+"?srcCode="+newCode+"&windowview=true";

	//var url = path+"?srcCode="+code+"&windowview=true";

	//End : Added by Prasad

	//alert("srinvas"+url);
	//window.open(url,"","height=500,width=700");

//	launchWindowWithMenubar(url,"sourcemgmt","height=500","width=700");
	//	launchWindowWithMenubar(url,"sourcemgmt","height=200","width=500");
	launchWindowWithMenubar(url,"sourcemgmt",height="900",width="700");




}


/*end of added by sameer for SIR 757 */

