// JScript File

//*****************************************************************
//This function is used to open a new browser window with different name
function PopUpPageWithDifferentName(PageURL,PageName,ScreenWidth,ScreenHeight)
{
    if (ScreenWidth == null)
	{
	    ScreenWidth=560;
	}
	if (ScreenHeight == null)
	{
	    ScreenHeight=350;
	}
	widths=ScreenWidth; //560;
	heights=ScreenHeight;//250;
	/*lefts=(screen.width/2)-280;
	tops=(screen.height/2)-230;*/
	lefts=(screen.width - widths) / 2;
	tops=(screen.height - heights) / 2;
	thepage=PageURL;
	thepagename=PageName;
	//alert(thepagename);
	newpage=window.open(thepage,thepagename,'scrollbars=yes,resizable=yes,Left='+lefts+',width='+widths+',height='+heights+',top='+tops+'');
	newpage.focus();
}
//*****************************************************************

//*****************************************************************
//function to store the value in specified hidden field as per
//confirm box.
function showConfirmAndStoreValueOpenUrl(controlIdToStoreValue,valueToStoreInControl,message,url,pageName,screenWidth,screenHeight,loadSomeCodeBehindControlId)
{
    var controlForStoringValue;
    controlForStoringValue = document.getElementById(controlIdToStoreValue);
    
    var confirmBoxAnswer;
    confirmBoxAnswer = confirm(message);
    
    var someControlId;
    someControlId = document.getElementById(loadSomeCodeBehindControlId);
    
    if (confirmBoxAnswer == true)
    {
        controlForStoringValue.value = '';
        controlForStoringValue.value = 'yes' + valueToStoreInControl;
        if (url!='nourl')
        {
            PopUpPageWithDifferentName(url,pageName,screenWidth,screenHeight);
        }
        else if (url=='nourl')
        {
            //here in this if statment there will be a linkbutton
            //id
            if (loadSomeCodeBehindControlId != null)
            {
                //someControlId = document.getElementById(loadSomeCodeBehindControlId);
                someControlId.click();
            }
        }
        
    }
    else
    {
        controlForStoringValue.value = '';
        controlForStoringValue.value = 'no' + valueToStoreInControl;
        //alert(someControlId);
        someControlId.click();
        
    }
    
}
//*****************************************************************

//*****************************************************************
//function to set focus on specified control
function setFocus(controlId)
{
    var controlToFocus;
    controlToFocus = document.getElementById(controlId);
    
    controlToFocus.focus();
}
//*****************************************************************

//*****************************************************************
//function to highlight text inside textbox
function highlightText(controlId)
{
    var controlToFocus;
    controlToFocus = document.getElementById(controlId);
    
    controlToFocus.select();
}
//*****************************************************************

//*****************************************************************
//showConfirm is just to show the confirm box on mousedown and if 
//user clicks ok or yes then control's server event will be fired if any
function showConfirm(controlId,hiddenFieldId,messageToDisplay)
{
    
    var control;
    control = document.getElementById(controlId);

    var confirmAnswer;
    confirmAnswer = confirm(messageToDisplay);
    
    if (confirmAnswer == true)
    {
        document.getElementById(hiddenFieldId).value = "true";
        control.click();
    }
    else
    {
        document.getElementById(hiddenFieldId).value = "false";
    }
}
//*****************************************************************

//*****************************************************************
//showConfirmOnKeyPress is just to show the confirm box onkeypress 
//and if user clicks ok or yes then control's server event will be 
//fired if any
function showConfirmOnKeyPress(controlId,hiddenFieldId,messageToDisplay)
{
    
    if (event.keyCode == 13)
    {
        var control;
        control = document.getElementById(controlId);

        var confirmAnswer;
        confirmAnswer = confirm(messageToDisplay);
        
        //alert(confirmAnswer);
        if (confirmAnswer == true)
        {
            document.getElementById(hiddenFieldId).value = "true";
            control.click();
        }
        else
        {
            document.getElementById(hiddenFieldId).value = "false";
        }
    }
    else
    {
        document.getElementById(hiddenFieldId).value = "false";
    }   
    
}
//*****************************************************************

//*****************************************************************
//function will just show hide the other control as per the 1st
//control's selected status
//checkReverse : this is used so that one can check flag in reverse
//manner also, false - normal and true - reverse
function showHideControlsOnDemand(flagControlId, showHideControlId, checkReverse)
{
    var parentControl;
    var showHideControl;
    
    parentControl = document.getElementById(flagControlId);
    showHideControl = document.getElementById(showHideControlId);
    
    if (checkReverse = false)
    {
        if (parentControl.checked == true)
        {
            showHideControl.style.visibility = 'visible';
        }
        else
        {
            showHideControl.style.visibility = 'hidden';
        }
    }
    else
    {
        if (parentControl.checked == true)
        {
            showHideControl.style.visibility = 'hidden';
        }
        else
        {
            showHideControl.style.visibility = 'visible';
        }
    }
}
//*****************************************************************


//*********************************************************************
//function below named CheckNumericWithDecimal() allows user to input
//only the numeric values with or without decimals in textbox
function CheckNumericWithDecimal()
{
    
    if (window.event.keyCode==46) 
    {
        window.event.keyCode = 46;
    }
    else if (!(window.event.keyCode >=48  && window.event.keyCode <=57))
    {
        window.event.keyCode = 0;
    }
}  
//*********************************************************************

//*********************************************************************
//function below named CheckNumeric() allows user to input
//only the numeric values decimals in textbox
function CheckNumeric()
{

    if 
    (!(window.event.keyCode >= 48  && window.event.keyCode <= 57))
    {
        window.event.keyCode = 0;
    }

}
//*********************************************************************

//*********************************************************************
//function CheckNumericWithOneDecimal allows user to input only
//numeric values and only one decimal point
function CheckNumericWithOneDecimal(controlId) 
{
	//* only allow numbers to be entered*//
	var controlToCheck = document.getElementById(controlId);
	var checkOK = "0123456789.";
	var checkStr = controlToCheck.value;
	var allValid = true;
	var allNum = "";
	var intNumberOfDecimalPoints;
	intNumberOfDecimalPoints = 0;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
		if (ch != ",")
			allNum += ch;
		
		if (ch == ".")
		{
				if (intNumberOfDecimalPoints==0)
				{
					intNumberOfDecimalPoints+=1 
				}
				else
				{
					allValid = false; 
					break;
				}
		}

	}
	if (!allValid)
	{
		alert("Please enter numeric values only.");
		intNumberOfDecimalPoints = 0;
		controlToCheck.value='';
		controlToCheck.focus();
		return (false);
	}
}
//*********************************************************************

//*********************************************************************
//function below named fixDecimals is used to get the fix number of
//decimal numbers after the point.
function fixDecimals(numberValue, numberOfPrecisions)
{
    var numberWithPrecision;
	//alert(numberOfPrecisions);
	numberWithPrecision = (parseFloat(numberValue)).toFixed(numberOfPrecisions);
	//alert(numberWithPrecision);
	if (isNaN(numberWithPrecision)==true)
	{
	    numberWithPrecision=0;
	}
	
	return numberWithPrecision
}
//*********************************************************************

//*********************************************************************
//function below named setFixDecimals is used to set the return value
//to the control whose id is passed.
function setFixDecimals(controlIdToSet, numberValue, numberOfPrecisions)
{
    var controlToSetValue;
    controlToSetValue = document.getElementById(controlIdToSet);
    //alert(fixDecimals(numberValueControlId, numberOfPrecisions));
    controlToSetValue.value = fixDecimals(numberValue, numberOfPrecisions);
    
}
//*********************************************************************

//*********************************************************************
//funtion to check the field are empty or not
function checkEmptyFields(controlId, message, buttonControl)
{
    var controlToFind;
    controlToFind = document.getElementById(controlId);
    
    var button;
    button = document.getElementById(buttonControl);

    if (controlToFind.value.length == 0)
    {
        alert(message);
    }
    else
    {
        button.click();
    }
}
//*********************************************************************

//*********************************************************************
//funtion to check the dropdownlist fields are empty or not
function checkEmptyListItems(controlId, message, buttonControl, invalidIndexToCheck, hiddenFieldId, confirmMessage)
{
    var controlToFind;
    controlToFind = document.getElementById(controlId);

    var button;
    button = document.getElementById(buttonControl);
    
    if (controlToFind.options[invalidIndexToCheck].selected == true)
    {
        alert(message);
    }
    else
    {
        if (confirmMessage != '' && confirmMessage != '')
        {
            showConfirm(buttonControl, hiddenFieldId, confirmMessage);
        }
        else
        {
            button.click();
        }
    }
}
//*********************************************************************

//*********************************************************************
//function MoveOption is used to move listbox item from source to
//destination listbox
function MoveOption(fromControlId, toControlId)
{
    var objSourceElement;
    var objTargetElement;
    
    objSourceElement = document.getElementById(fromControlId);
    objTargetElement = document.getElementById(toControlId);
    
    var aryTempSourceOptions = new Array();
    var x = 0;
    //looping through source element to find selected options        
    for (var i = 0; i < objSourceElement.length; i++) 
    {//start of for
        if (objSourceElement.options[i].selected) 
        {//start of if within for
            //need to move this option to target element
            var intTargetLen = objTargetElement.length++;
            objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
            objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
        }//end of if within for          
        else//else of if within for
        {//start of else of if within for
            //storing options that stay to recreate select element 
            var objTempValues = new Object();  
            objTempValues.text = objSourceElement.options[i].text;  
            objTempValues.value = objSourceElement.options[i].value; 
            aryTempSourceOptions[x] = objTempValues;         
            x++;        
        }//end of else of if within for
    }//end of for
    //resetting length of source  
    objSourceElement.length = aryTempSourceOptions.length;
    //looping through temp array to recreate source select element
    for (var i = 0; i < aryTempSourceOptions.length; i++) 
    {//start of for
        objSourceElement.options[i].text = aryTempSourceOptions[i].text;  
        objSourceElement.options[i].value = aryTempSourceOptions[i].value; 
        objSourceElement.options[i].selected = false; 
    }//end of for
    
}//end of function
//*********************************************************************

//*********************************************************************
//function StoreIds is used to store ids into hidden field 
//from the control specified
function StoreIds(leftListBoxId, rightListBoxId, hiddenFieldIdLeft, hiddenFieldIdRight)
{
    var leftListId;
    leftListId = document.getElementById(leftListBoxId);

    var rightListId;
    rightListId = document.getElementById(rightListBoxId);
    
    var hiddenFieldLeft;
    hiddenFieldLeft = document.getElementById(hiddenFieldIdLeft);

    var hiddenFieldRight;
    hiddenFieldRight = document.getElementById(hiddenFieldIdRight);
    
    hiddenFieldLeft.value = "";
    hiddenFieldRight.value = "";
    
    //For left side control
    for (var i=0; i < leftListId.length; i++)
    {
        if (hiddenFieldLeft.value == "")
        {
            hiddenFieldLeft.value = leftListId.options[i].value;
        }
        else
        {
            hiddenFieldLeft.value += "," + leftListId.options[i].value;
        }
    }

    //For right side control
    for (var i=0; i < rightListId.length; i++)
    {
        if (hiddenFieldRight.value == "")
        {
            hiddenFieldRight.value = rightListId.options[i].value;
        }
        else
        {
            hiddenFieldRight.value += "," + rightListId.options[i].value;
        }
    }
    
}
//*********************************************************************

//*********************************************************************
// function moveUpWard is used to move listitem in a listbox towards up
function moveUpWard(listBoxControlId) 
{
    var listField;
    listField = document.getElementById(listBoxControlId);
    
   if ( listField.length == -1) {  // If the list is empty
      alert("There are no values which can be moved!");
   } else {
      var selected = listField.selectedIndex;
      if (selected == -1) {
         alert("You must select an entry to be moved!");
      } else {  // Something is selected 
         if ( listField.length == 0 ) {  // If there's only one in the list
            alert("There is only one entry!\nThe one entry will remain in place.");
         } else {  // There's more than one in the list, rearrange the list order
            if ( selected == 0 ) {
               alert("The first entry in the list cannot be moved up.");
            } else {
               // Get the text/value of the one directly above the hightlighted entry as
               // well as the highlighted entry; then flip them
               var moveText1 = listField[selected-1].text;
               var moveText2 = listField[selected].text;
               var moveValue1 = listField[selected-1].value;
               var moveValue2 = listField[selected].value;
               listField[selected].text = moveText1;
               listField[selected].value = moveValue1;
               listField[selected-1].text = moveText2;
               listField[selected-1].value = moveValue2;
               listField.selectedIndex = selected-1; // Select the one that was selected before
            }  // Ends the check for selecting one which can be moved
         }  // Ends the check for there only being one in the list to begin with
      }  // Ends the check for there being something selected
   }  // Ends the check for there being none in the list
}
//*********************************************************************

//*********************************************************************
// function moveDownWard is used to move listitem in a listbox towards down
function moveDownWard(listBoxControlId) 
{
    var listField;
    listField = document.getElementById(listBoxControlId);
    
   if ( listField.length == -1) {  // If the list is empty
      alert("There are no values which can be moved!");
   } else {
      var selected = listField.selectedIndex;
      if (selected == -1) {
         alert("You must select an entry to be moved!");
      } else {  // Something is selected 
         if ( listField.length == 0 ) {  // If there's only one in the list
            alert("There is only one entry!\nThe one entry will remain in place.");
         } else {  // There's more than one in the list, rearrange the list order
            if ( selected == listField.length-1 ) {
               alert("The last entry in the list cannot be moved down.");
            } else {
               // Get the text/value of the one directly below the hightlighted entry as
               // well as the highlighted entry; then flip them
               var moveText1 = listField[selected+1].text;
               var moveText2 = listField[selected].text;
               var moveValue1 = listField[selected+1].value;
               var moveValue2 = listField[selected].value;
               listField[selected].text = moveText1;
               listField[selected].value = moveValue1;
               listField[selected+1].text = moveText2;
               listField[selected+1].value = moveValue2;
               listField.selectedIndex = selected+1; // Select the one that was selected before
            }  // Ends the check for selecting one which can be moved
         }  // Ends the check for there only being one in the list to begin with
      }  // Ends the check for there being something selected
   }  // Ends the check for there being none in the list
}
//*********************************************************************

//*********************************************************************
//function MoveOption is used to store ids into hidden field 
//from the control specified
function StoreManulDisplayOrderIds(listBoxControlId, hiddenFieldControlId)
{
    var listBoxId;
    listBoxId = document.getElementById(listBoxControlId);

    var hiddenFieldId;
    hiddenFieldId = document.getElementById(hiddenFieldControlId);

    hiddenFieldId.value = "";
        
    //For list box control
    for (var i=0; i < listBoxId.length; i++)
    {
        if (hiddenFieldId.value == "")
        {
            hiddenFieldId.value = listBoxId.options[i].value;
        }
        else
        {
            hiddenFieldId.value += "," + listBoxId.options[i].value;
        }
    }
}
//*********************************************************************

//*********************************************************************
// selectOne function is used to select only one checkbox/radio button with in
// a grid
//value for radioOrCheckBoxId will be radio/checkbox client id
//value for gridName will be datagrid or any datacontrol's client id
//value for markCheckedSelected will be true(mark clicked control checked), false(mark clicked control unchecked)
//value for radioOrCheckBox will be 1(radio) or 2(checkbox)
var strPreviousControlId;
strPreviousControlId='';
function selectOne(radioOrCheckBoxId,gridName,markCheckedSelected,radioOrCheckBox)
{//start of function
    
    var controlId;
    controlId = document.getElementById(radioOrCheckBoxId);
    var controlInitialState;
    controlInitialState = controlId.checked;
    
    all=document.getElementsByTagName("input");/* Getting an array of all the "INPUT" controls on the form.*/
 
    for(i=0;i<all.length;i++)
    {//start of for 1
        if(radioOrCheckBox==1)//if statement for radiobutton
        {//start of radiobutton's if
            if(all[i].type=="radio")/*Checking if it is a radio button*/
            {//start of if 1
                var count=all[i].id.indexOf(gridName+'_ctl'); /*I have added '_ctl' ASP.NET adds '_ctl' to all the controls of DataGrid.*/
                if(count!=-1)
                {//start of if 2
                    all[i].checked=false;
                }//end of if 2
            }//end of if 1    
        }//end of radiobutton's if
        else if(radioOrCheckBox==2)//if statement for checkbox
        {
            if(all[i].type=="checkbox")/*Checking if it is a checkbox*/
            {//start of if 1
                var count=all[i].id.indexOf(gridName+'_ctl'); /*I have added '_ctl' ASP.NET adds '_ctl' to all the controls of DataGrid.*/
                if(count!=-1)
                {//start of if 2
                    all[i].checked=false;
                }//end of if 2
            }//end of if 1    
        }
    }//end of for 1

    if (markCheckedSelected == true)    
    {//start of if (markCheckedSelected == true)
        controlId.checked=true;/* Finally making the selected radiobutton/checkbox CHECKED */
    }//end of if (markCheckedSelected == true)
    else
    {//start of else of (markCheckedSelected == true)
        if (strPreviousControlId==controlId.id)
        {//start of if (strPreviousControlId==controlId.id)
            if (controlInitialState==true)
            {//start of if (controlInitialState==true)
                controlId.checked=true;
                strPreviousControlId=controlId.id;
            }//end of if (controlInitialState==true)
            else
            {//start of else of (controlInitialState==true)
                controlId.checked=false;
                strPreviousControlId=controlId.id;
            }//end of else of (controlInitialState==true)
        }//end of if (strPreviousControlId==controlId.id)
        else
        {//start of else of (strPreviousControlId==controlId.id)
            controlId.checked=true;
            strPreviousControlId=controlId.id;
        }//end of else of (strPreviousControlId==controlId.id)
    }//end of else of (markCheckedSelected == true)
    
}//end of function
//*********************************************************************

//*********************************************************************
// function validatePresentOrNewData will check weather user has selected
// or enter values or not.
// dropdownlistId: dropdownlist control id
// textboxId: textbox control id
// alertMessage: alert message to show
function validatePresentOrNewData(dropdownlistId,textboxId,alertMessage)
{
    var ddlId;
    var txtId;
    ddlId = document.getElementById(dropdownlistId);
    txtId = document.getElementById(textboxId);
    
    if (ddlId.selectedIndex == 0 && trim(txtId.value) == '')
    {
        alert(alertMessage);
        setFocus(ddlId.id);
        return false;
    }
    else if (ddlId.selectedIndex != 0 && trim(txtId.value) != '')
    {
        alert(alertMessage);
        setFocus(ddlId.id);
        return false;
    }
    else
    {return true;}
}
//*********************************************************************

//*********************************************************************
// function validatePresentData will check weather user has selected
// value or not.
// dropdownlistId: dropdownlist control id
// alertMessage: alert message to show
function validatePresentData(dropdownlistId,alertMessage)
{
    var ddlId;
    ddlId = document.getElementById(dropdownlistId);
    
    if (ddlId.selectedIndex == 0)
    {
        alert(alertMessage);
        setFocus(ddlId.id);
        return false;
    }
    else
    {return true;}
    
}
//*********************************************************************

//*********************************************************************
// trim() function will be used to remove leading or trailing space from
// the provided string
function trim(stringToTrim)
{
    stringToTrim = stringToTrim.replace(/^\s+|\s+$/g, '');
    return stringToTrim;
}
//*********************************************************************

//*********************************************************************
// setDefaultTextBoxValue() and removeDefaultTextBoxValue() will be used
// for setting default text within textbox and to remove from the textbox
// respectivly
function setDefaultTextBoxValue(controlId, valueToSet)
{
    var textBoxControl;
    textBoxControl = document.getElementById(controlId);
    if (textBoxControl.value == '')
        textBoxControl.value = valueToSet;
}
function removeDefaultTextBoxValue(controlId, valueToSet)
{
    var textBoxControl;
    textBoxControl = document.getElementById(controlId);
    if (textBoxControl.value == valueToSet)
        textBoxControl.value = '';
}
//*********************************************************************
//*********************************************************************
//This function is used to check "OR" condition of controls in CustomEflyerClientDetails.aspx.cs
//on keypress & mousedown events of button preview and Save & email
function checkForm(ClientnameId,Textid,FileUploadLogoImageId,EflyerNameId)
{
    var textBoxClientnameControl;
    var textBoxTextControl;
    var fileUploadControl;
    var textBoxEflyerNameControl;
    textBoxClientnameControl = document.getElementById(ClientnameId);
    textBoxTextControl = document.getElementById(Textid);
    fileUploadControl = document.getElementById(FileUploadLogoImageId);
    textBoxEflyerNameControl = document.getElementById(EflyerNameId);
    
    if (textBoxClientnameControl.value == "" && textBoxTextControl.value == "")
    {
        alert("Plese select any one option - Either upload a logo or Enter text for the Eflyer!");
        return false;
    }
    else if (textBoxClientnameControl.value != "" && fileUploadControl.value != "" && textBoxTextControl.value != "")
    {
        alert("Plese select any one option - Either upload a logo or Enter text for the Eflyer!")
        return false;
    }
    else if (textBoxClientnameControl.value != "" && fileUploadControl.value == "")
    {
        alert("Plese select any one option - Either upload a logo or Enter text for the Eflyer!")
        return false;
    }
    else if (textBoxEflyerNameControl.value == "") //as Eflyer name is compulsory
    {
        alert("Please enter a name for the Eflyer");
        return false;
    }
    else
    {
        return true;
    }
}
//*********************************************************************

//*********************************************************************
//*********************************************************************
//function below named changeProductImage is used to show product image
//but on click of the variation name of a variant
function changeProductImage(imageControlId, fullyQulifiedImageName, hiddenFieldId, hiddenFieldValueToSet, hiddenFieldForCurrentImageURL)
{
    var objProductImage;
    objProductImage = document.getElementById(imageControlId);
    objProductImage.src = fullyQulifiedImageName;
    
    var hiddenControlForCurrentImageURL;
    hiddenControlForCurrentImageURL = document.getElementById(hiddenFieldForCurrentImageURL);
    hiddenControlForCurrentImageURL.value = fullyQulifiedImageName;
    
    var imageName;
    imageName = fullyQulifiedImageName.split('/');
    
    var imageId;
    imageId = imageName[imageName.length - 1].split('.')
                            
    var hiddenControl;
    hiddenControl = document.getElementById(hiddenFieldId);
    if ( (fullyQulifiedImageName.indexOf('Variant') != -1) || (fullyQulifiedImageName.indexOf('variant') != -1) )
    {
        hiddenControl.value = hiddenFieldValueToSet + '&vid=' + imageId[0];
    }
    else
    {
        hiddenControl.value = hiddenFieldValueToSet;
    }
    
}
//*********************************************************************

//*********************************************************************
//function below named popUpProductImage is used to show product's zoom image
function popUpProductImage(hiddenFieldId)
{
    var hiddenControl;
    hiddenControl = document.getElementById(hiddenFieldId);
    
    PopUpPageWithDifferentName('ProductZoomImage.aspx' + hiddenControl.value,'ViewProductZoomImage',570,580);
}
//*********************************************************************
//*********************************************************************
//function below named showColorPicker is used to show color picker
function showColorPicker(colorPickerParentDirectoryPath, textboxControlId)
{
    var controlId;
    controlId = document.getElementById(textboxControlId);
    
    if (controlId!=null)
        CP.popup(colorPickerParentDirectoryPath + 'Scripts/ColorPicker/ColorPicker.html', controlId, 1);
}
//*********************************************************************

//*********************************************************************
//function below named RefreshParentCloseChild will refresh opener parent
function RefreshParentCloseChild(parentUrl)
{
//window.opener.document.forms[0].action= a 
//window.opener.document.forms[0].submit();
window.opener.location.href = parentUrl;
self.close();
}
//*********************************************************************
//*********************************************************************
// To check the minimum quantity for Order Cart page
//*********************************************************************
function CheckMinimumQuantity(minval,clientId)
{
    var qnty = document.getElementById(clientId).value;
	if ( parseInt(qnty) < parseInt(minval) || qnty == "" )
	{
	alert(" Quantity should be greater than minimum quantity !! ");
	document.getElementById(clientId).focus();
	return false;
	}
}
//*********************************************************************

//*********************************************************************
//*********************************************************************
// function below named go_etracking is redirecting to order tracking site
//*********************************************************************
function go_etracking()
{
 var where_to= confirm("This will take you an external site.Please close the window to return to original site.Do you wish to continue??");
 if (where_to== true)
 {
   window.open("http://wwwapps.ups.com/etracking/tracking.cgi");
 }
 else
 {
 
  }
}
//*********************************************************************

//*********************************************************************
//*********************************************************************
// function below named go_etracking is redirecting to order tracking site
//*********************************************************************
function go_eFedEx()
{
 var where_to= confirm("This will take you an external site.Please close the window to return to original site.Do you wish to continue??");
 if (where_to== true)
 {
   window.open("http://www.fedex.com/Tracking");
 }
 else
 {
 
  }
}
function checkpaymentinformation( paymenttype )
{
    //if (paymenttype == 'purchase order')
    //{
        alert(' Purchase Order Number cannot be Empty !!');
        return false;
   // }
   // else
    //    return true;
    
}

//*********************************************************************
//*********************************************************************
// function below named telnumchk is validating the telephone number
//*********************************************************************

function telnumchk() 
{
	event.keyCode=TelDisallowChar(event.keyCode);
	
	
}
//*********************************************************************

//*********************************************************************
//*********************************************************************
// function below named TelDisallowChar is disallowing characters
//*********************************************************************

function TelDisallowChar(keyPressed)
{
	if (keyPressed>=48 && keyPressed<=57 || keyPressed==45)
	{
	}
	else
	{
		alert("Please Enter Numbers only");
		keyPressed = 0
	}
		return keyPressed	
}
//*********************************************************************

//*********************************************************************
//*********************************************************************
// function below named CheckIsNumber is validating the input as number
//*********************************************************************

function CheckIsNumber(obj)
{
if (isNaN(obj.value)){
obj.value="";
alert("Enter valid Number");
return false;
}
return true;
}
//*********************************************************************
// To Print the Page
//*********************************************************************
function windowprint(productid,x)
	{
		//window.open("printpage.asp");
		window.print();
	}
//*********************************************************************

//*********************************************************************

/////////////////////////////////////////////////////////////////////
/// THIS select_deselectAll FUNCTION IS FOR SELECTING/DESELECTING //
/// THE CHECKBOX FOR SELECTING/DESELECTING ALL CHECKBOXES IN GRID /
//////////////////////////////////////////////////////////////////
// way to implement
// <INPUT id="checkboxPickAll" onclick="javascript: return select_deselectAll (this.checked, this.id,'checkboxContact');" type="checkbox" name="checkboxPickAll">

function select_deselectAll (chkVal, idVal, idChildVal) 
{ 

    var frm = document.forms[0];
    // Loop through all elements
  
    for (i=0; i<frm.length; i++) 
    {
    
		var str = frm.elements[i].id;
		var abc = str.split("_")
		//alert(abc[4]); --abc[4] means server checkbox id
		
        // Look for our Header Template's Checkbox
        if (idVal.indexOf ('checkboxPickAll') != -1) 
        {
        			
            // Check if main checkbox is checked, then select or deselect datagrid checkboxes 
            if(chkVal == true) 
            { 				
				if (abc[4] == idChildVal)
				{
					frm.elements[i].checked = true;
				}
            } 
            else 
            {
                if (abc[4] == idChildVal)
				{
					frm.elements[i].checked = false;
				}
            }
            // Work here with the Item Template's multiple checkboxes
        } 
        else if (idVal.indexOf ('checkPickAll') != -1) 
        {
            // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
            if(chkVal == true) 
            {
                if (abc[4] == idChildVal)
				{
					frm.elements[i].checked = true;
				}
            }
            else
            {
				if (abc[4] == idChildVal)
				{
					frm.elements[i].checked = false;
				}
            }
        }
    }

}
//*********************************************************************

function BrowsekeyChk()
{
    var frm = document.forms[0];
    alert("Please click on BROWSE to select the file !!!");
	document.frm.fleupdLogoImage.PostedFile.FileName="";
	//document.frm.fleupdLogoImage.blur();
}
function keyval1()
{
	if ((event.keyCode==8)||(event.keyCode==46))
	{
		event.returnValue=false;

	}		
}


//*********************************************************************
//function below named popUpVirtualProductImage is used to show product's virtual sample image
function popUpVirtualProductImage(hiddenFieldId)
{
    var hiddenControl;
    hiddenControl = document.getElementById(hiddenFieldId);
    
    PopUpPageWithDifferentName('http://www.fastbadge.com/vs.asp?from=VS&ProdId=' + hiddenFieldId +'&vsImg='+ hiddenFieldId +'.jpg','fastbadge',520,750);
}
//*********************************************************************


//Function added for Holders Alert

function CheckHoldersQty(qty)
 {
   
 
       
    var table1=document.getElementById("ctl00_cphTemplateContent_grdOptionalGrid");
   
    
    
    
    var blnTrue=true;
    var intChecked = 0;
    var intQty = 0;
    var intTotalQty = 0;
    var MinimumQty = parseInt(qty);
    var boolResult=false;
    var messgae = "";
    var iResult = 0;
    var name = "";
    if(table1 != null)
    {
        var eleArray = table1.getElementsByTagName("input");
        for(var i=0;i<eleArray.length;i++)
        {
            name = eleArray[i].name;
           if(name.indexOf("lblOptionalUnitPrice") < 0 )
           {
                if(eleArray[i].type=="text")
                {
                     if(eleArray[i].value != "")
                     {
                        intQty =  parseInt(eleArray[i].value);
                     }
                     else
                     {
                        intQty = 0;
                     }
                    intTotalQty += intQty;
                }
            }

        }//end of for 
     }
     
    // alert("grdOptionalGrid " + intTotalQty);
        var table2=document.getElementById("ctl00_cphTemplateContent_grdFrames");
      
       
     if(table2 != null)
    {
         eleArray = table2.getElementsByTagName("input");
         
        for(var i=0;i<eleArray.length;i++)
        {
           name = eleArray[i].name;
           if(name.indexOf("lblFramesUnitPrice") < 0 )
           {
                if(eleArray[i].type=="text")
                {
                     if(eleArray[i].value != "")
                     {
                        intQty =  parseInt(eleArray[i].value);
                     }
                     else
                     {
                        intQty = 0;
                     }
                    intTotalQty += intQty;
                }
            }
       

        }//end of for 
        
      
     }
     //alert("grdFrames " + intTotalQty);
     
     if(table1 == null || table2 == null)
     {
         var bResult = true;
     }
      //alert("intTotalQty >= qty" + intTotalQty+ ">="+ qty);
       if( qty > intTotalQty && (table1 != null || table2 != null) ) 
        bResult = confirm("Selected Holders and Frame Quantity is Less than Product Quantity. \r\nAre you sure you would like to continue?\r\n Press Ok To Continue And Cancel To Return To Order");
        else 
        bResult = true;
        
        return bResult;
}



//function added for validation of version 

function CheckVersions(gridID,qty)
 {
   
       
    var table=document.getElementById(gridID);
    var eleArray = table.getElementsByTagName("input");
    var blnTrue=true;
    var intChecked = 0;
    var intQty = 0;
    var intTotalQty = 0;
    var MinimumQty = parseInt(qty);
    var boolResult=false;
    var messgae = "";
    var iResult = 0;
    var name = "";
    
        for(var i=0;i<eleArray.length;i++)
        {
           
            if(eleArray[i].type=="checkbox")
            {
                if(eleArray[i].checked)
                {
                    intChecked = intChecked + 1;
                }
            }
        
             if(eleArray[i].type=="text")
            {
               name = eleArray[i].name;
               if(name.indexOf("lblVersionUnitPrice") < 0 )
               {
                     if(eleArray[i].value != "")
                     {
                        intQty =  parseInt(eleArray[i].value);
                     }
                     else
                     {
                        intQty = 0;
                     }
                    intTotalQty += intQty;
                }
            }

        }//end of for 
         
         
         if(!CheckHoldersQty(intTotalQty))
         {
            iResult = iResult + 1;
         }
        
      
        
            if(intTotalQty >=  MinimumQty)
            {
             
            }
            else
            {
                messgae = "Minimum Quantity For This Product Is : " + MinimumQty;
                 iResult = iResult + 1;
            }

          //alert(iResult);
        if( iResult == 0)
        {
           //alert(iResult);
            boolResult= validatePage();
           // alert(validatePage());
            
            //validatePage();
        }
        else
        {
            if(messgae != "")
            alert(messgae);
        }
        
        return boolResult;
  
}

function validatePage()
{
    //Order Contact
    var txtSoldCompany = document.getElementById("ctl00_cphTemplateContent_txtSoldCompany");
    var txtSoldContact = document.getElementById("ctl00_cphTemplateContent_txtSoldContact");
    var txtSoldAdd1 = document.getElementById("ctl00_cphTemplateContent_txtSoldAdd1");
    var txtSoldCity = document.getElementById("ctl00_cphTemplateContent_txtSoldCity");
    var txtSoldState = document.getElementById("ctl00_cphTemplateContent_txtSoldState");
    var txtSoldZip = document.getElementById("ctl00_cphTemplateContent_txtSoldZip");
    var txtSoldPh = document.getElementById("ctl00_cphTemplateContent_txtSoldPh");
    var txtSoldEmail = document.getElementById("ctl00_cphTemplateContent_txtSoldEmail");
    var drpSoldCountry = document.getElementById("ctl00_cphTemplateContent_drpSoldCountry");
    //bill To
    var txtBillToCompany = document.getElementById("ctl00_cphTemplateContent_txtBillToCompany");
    var txtBillToContact = document.getElementById("ctl00_cphTemplateContent_txtBillToContact");
    var txtBillToAdd1 = document.getElementById("ctl00_cphTemplateContent_txtBillToAdd1");
    var txtBillToCity = document.getElementById("ctl00_cphTemplateContent_txtBillToCity");
    var txtBillToState = document.getElementById("ctl00_cphTemplateContent_txtBillToState");
    var txtBillToZipCode = document.getElementById("ctl00_cphTemplateContent_txtBillToZipCode");
    var ddlBillToCountry = document.getElementById("ctl00_cphTemplateContent_ddlBillToCountry");

     //ship To
    var txtShipToCompany = document.getElementById("ctl00_cphTemplateContent_txtShipToCompany");
    var txtShipToContact = document.getElementById("ctl00_cphTemplateContent_txtShipToContact");
    var txtShipToAdd1 = document.getElementById("ctl00_cphTemplateContent_txtShipToAdd1");
    var txtShipToCity = document.getElementById("ctl00_cphTemplateContent_txtShipToCity");
    var txtShipToState = document.getElementById("ctl00_cphTemplateContent_txtShipToState");
    var txtShipToZip = document.getElementById("ctl00_cphTemplateContent_txtShipToZip");
    var ddlShipToCountry = document.getElementById("ctl00_cphTemplateContent_ddlShipToCountry");
    
    
    //For Order For Users 
    
    var drpUsers = document.getElementById("ctl00_cphTemplateContent_drpUsers");
   
    //for size 
    var txtProductSize = document.getElementById("ctl00_cphTemplateContent_txtProductSize");
    var ddlProductSize = document.getElementById("ctl00_cphTemplateContent_ddlProductSize");
    
    // for Matarial 
    //ctl00_cphTemplateContent_grdProductOptions_ctl02_ddlProductOption
    var ddlProductOption = document.getElementById("ctl00_cphTemplateContent_grdProductOptions_ctl02_ddlProductOption");
    
    //for ImprintColor
    
    var ddlImprint = document.getElementById("ctl00_cphTemplateContent_grdProductOptions_ctl03_ddlProductOption");
    //logo Name
    
    var txtLogoName = document.getElementById("ctl00_cphTemplateContent_txtLogoName");
    
    //Name List Type 
     var drpNameList = document.getElementById("ctl00_cphTemplateContent_drpNameList");
     
      //Payment Method
     var ddlPaymentInfo = document.getElementById("ctl00_cphTemplateContent_ddlPaymentInfo");
    
    
    
    //Date Validation 
    var txtRequiredInHands = document.getElementById("ctl00_cphTemplateContent_txtRequiredInHands");
    
    //for Reorder Validation 
    var chkReorder = document.getElementById("ctl00_cphTemplateContent_chkReorder");
    var txtRePO = document.getElementById("ctl00_cphTemplateContent_txtRePO");
    var txtReOrderNo = document.getElementById("ctl00_cphTemplateContent_txtReOrderNo");
    
   //Order For 
   var drpOrderFor = document.getElementById("ctl00_cphTemplateContent_drpOrderFor");
    
    var iResult = 0;
    
    var ErrorMsg= "";

    if(txtSoldCompany.value == "")
    {
        ErrorMsg = " - Enter Order Contact Company \r\n";
        iResult = iResult + 1;
    }
    if(txtSoldContact.value == "")
    {
        ErrorMsg += " - Enter Order Contact Contact \r\n";
        iResult = iResult + 1;
    }
    if(txtSoldAdd1.value == "")
    {
        ErrorMsg += " - Enter Order Contact Address1 \r\n";
        iResult = iResult + 1;
    }
    if(txtSoldCity.value == "")
    {
        ErrorMsg += " - Enter Order Contact City \r\n";
        iResult = iResult + 1;
    }
    if(txtSoldState.value == "")
    {
        ErrorMsg += " - Enter Order Contact State \r\n";
        iResult = iResult + 1;
    }
    if(drpSoldCountry.value == "0")
    {
        ErrorMsg += " - Enter Order Contact Country \r\n";
        iResult = iResult + 1;
    }
   
    if(txtSoldZip.value == "")
    {
        ErrorMsg += " - Enter Order Contact Zip Code \r\n";
        iResult = iResult + 1;
    }
    if(txtSoldPh.value == "")
    {
        ErrorMsg += " - Enter Order Contact Phone \r\n";
        iResult = iResult + 1;
    }
    if(txtSoldEmail.value == "")
    {
        ErrorMsg += " - Enter Order Contact Email \r\n";
        iResult = iResult + 1;
    }
    //bill To 
    
    if(txtBillToCompany.value == "")
    {
        ErrorMsg += " - Enter Bill To Company \r\n";
        iResult = iResult + 1;
    }
    if(txtBillToContact.value == "")
    {
        ErrorMsg += " - Enter Bill To Contact \r\n";
        iResult = iResult + 1;
    }
    if(txtBillToAdd1.value == "")
    {
        ErrorMsg += " - Enter Bill To Address1 \r\n";
        iResult = iResult + 1;
    }
    if(txtBillToCity.value == "")
    {
        ErrorMsg += " - Enter Bill To City \r\n";
        iResult = iResult + 1;
    }
    if(txtBillToState.value == "")
    {
        ErrorMsg += " - Enter Bill To State \r\n";
        iResult = iResult + 1;
    }
    if(txtBillToZipCode.value == "")
    {
        ErrorMsg += " - Enter Bill To Zip Code \r\n";
        iResult = iResult + 1;
    }
     if(ddlBillToCountry.value == "0")
    {
        ErrorMsg += " - Enter Bill To Country \r\n";
        iResult = iResult + 1;
    }


    //shipto To 
    
    if(txtShipToCompany.value == "")
    {
        ErrorMsg += " - Enter Ship To Company \r\n";
        iResult = iResult + 1;
    }
    if(txtShipToContact.value == "")
    {
        ErrorMsg += " - Enter Ship To Contact \r\n";
        iResult = iResult + 1;
    }
    if(txtShipToAdd1.value == "")
    {
        ErrorMsg += " - Enter Ship To Address1 \r\n";
        iResult = iResult + 1;
    }
    if(txtShipToCity.value == "")
    {
        ErrorMsg += " - Enter Ship To City \r\n";
        iResult = iResult + 1;
    }
    if(txtShipToState.value == "")
    {
        ErrorMsg += " - Enter Ship To State \r\n";
        iResult = iResult + 1;
    }
    if(txtShipToZip.value == "")
    {
        ErrorMsg += " - Enter Ship To Zip Code \r\n";
        iResult = iResult + 1;
    }
     if(ddlShipToCountry.value == "0")
    {
        ErrorMsg += " - Enter Ship To Country \r\n";
        iResult = iResult + 1;
    }
   // alert("ddlShipToCountry.value = " + ddlShipToCountry.value);
    //Logoname
    
      if(txtLogoName.value == "")
    {
        ErrorMsg += " - Enter Logo Name \r\n";
        iResult = iResult + 1;
    }
    
    if(txtRequiredInHands.value != "")
    {
        if(!isValidDate(txtRequiredInHands.value))
        {
            ErrorMsg += " - Enter Vallid Requireds In Hands Date \r\n";
            iResult = iResult + 1;
        }
    }
    
    //for size 
    if(txtProductSize != null)
    {
        if(txtProductSize.value="")
        {
            ErrorMsg += " - Please Enter Product Size. \r\n";
                iResult = iResult + 1;
        }
    }
    
    if(ddlProductSize != null)
    {
        if(ddlProductSize.value =="0")
        {
             ErrorMsg += " - Please Select Product Size. \r\n";
                iResult = iResult + 1;
        }
    }
    //For Order For 
    
    if(drpOrderFor != null)
    {
        if(drpOrderFor.value =="0")
        {
             ErrorMsg += " - Please Select User To Order For. \r\n";
                iResult = iResult + 1;
        }
    }
    
    //For Imprint
    if(ddlImprint != null)
    {
    
        if(ddlImprint.value =="0")
        {
        //alert(ddlProductOption.value);
             ErrorMsg += " - Please Select Imprint Color. \r\n";
                iResult = iResult + 1;
        }
    }
    
    //for material 
    if(ddlProductOption != null)
    {
    
        if(ddlProductOption.value =="0")
        {
        //alert(ddlProductOption.value);
             ErrorMsg += " - Please Select Material Color. \r\n";
                iResult = iResult + 1;
        }
    }
    // alert(" chkReorder "+ chkReorder.checked);
     if(chkReorder != null)
     {
         if(chkReorder.checked)
         {
            if(txtRePO.value == "" && txtReOrderNo.value =="")
            {
                ErrorMsg += " - Enter Previous PO# OR Order# \r\n";
                iResult = iResult + 1;
            }
         }
     }
     if(drpNameList != null)
     {
        if(drpNameList.value == "0")
        {
            ErrorMsg += " - Please Select Name List Type. \r\n";
            iResult = iResult + 1;
        }
     }

    if(ddlPaymentInfo != null)
    {
        if(ddlPaymentInfo.value == "0")
        {
            ErrorMsg += " - Please Select Payment Method. \r\n";
            iResult = iResult + 1;
        }
    }

    
    if(drpUsers != null)
    {
        if(drpUsers.value == "0")
        {
            ErrorMsg += " - Please Select Your Customer. \r\n";
            iResult = iResult + 1;
        }
    }
   // alert(iResult);
    if(iResult > 0)
    {   
        alert(ErrorMsg);
        return false;
    }
    else
    {
        return true;
    }
    
}

function ValidateHoldersForRelease(grdHoldersId,dtlstPersonaliseID,IsNormalOrder)
 {
   
      var grdHolders =document.getElementById(grdHoldersId);
      var dtlstPersonalise =document.getElementById(dtlstPersonaliseID);
      
       var stringQty  = 'txtReleaseQty';
       var iId=2;
        
        var selectedHolder ="";
        var selectedQty ="";
        var blnResult = true;
        if(grdHolders != null)
        {
            for(var i=0;i<grdHolders.rows.length;i++)
            {
                var  id  = "ctl00$cphTemplateContent$grdvwReleaseHolders$ctl0"+ iId +"$txtReleaseQty";
                var id2 = "ctl00_cphTemplateContent_grdvwReleaseHolders_ctl0"+iId+"_lblItemName";
                //var id3 = "ctl00_cphTemplateContent_grdvwReleaseHolders_ctl0"+iId+"_lblProductId";
                var HolderQty = document.getElementById(id);
                var lblItemName  = document.getElementById(id2);
                //var ProductId  = = document.getElementById(id3);
               
                if(HolderQty  != null && lblItemName != null)
                {

                        selectedHolder =lblItemName.innerText
                        if(HolderQty.value!="")
                        {
                            selectedQty =parseInt(HolderQty.value);
                        }
                        else
                        {
                            selectedQty =parseInt(0);
                        }
                        
                        blnResult = ValidatePesonalizeDetailsForRelease(dtlstPersonalise,selectedHolder,selectedQty,IsNormalOrder);
                        if(!blnResult)
                        {
                            break;
                        }
                        //alert("Result : " + blnResult);
                    //}
                    iId = iId +1 ;
                }
              
                
          }//end of for
      }//End Null obj
      return blnResult; 
      
 }


function ValidatePesonalizeDetailsForRelease(dtlstPersonalise,selectedHolder,selectedQty,IsNormalOrder)
 {
  // alert('selectedHolder ' + selectedHolder + 'selectedQty ' +selectedQty);
      var eleArray = dtlstPersonalise.getElementsByTagName("Select");
         var element = null;
         var iHolders = 0;
         
            for(var i=0;i<eleArray.length;i++)
            {
                if(eleArray[i].value != "" )
                {
                    
                    if(eleArray[i].options[eleArray[i].selectedIndex].text == selectedHolder)
                    {
                      iHolders = iHolders+1;
                      if(iHolders > selectedQty)
                        {
                            eleArray[i].selectedIndex=0;
                        }
                    }
                   
                }
        

            }//end of for 
       
       // alert(iHolders + " > " + selectedQty)
        if(iHolders > selectedQty)
        {
            //if(IsNormalOrder != "True")
            alert("Note : Total Number Of Optional Holders/Frames Is Not Equal To Total Products Released.");
            return false;
        }
        else
        {
           
            return true;
        }
        
      
 }
 
 //New Script Added
 
function isValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
//alert("Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
//alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
//alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
//alert("February " + year + " doesn't have " + day + " days!");
return false;
}
}
return true;  // date is valid
}

