// JavaScript Document
function delete_rec()
{
	var confans;
	confans=confirm("Are you sure you want to delete this record?")
	if(confans)
	{    
		return true;
	}
	else
	{
		return false;
	}
}
function generateKey()
{
	var confans;
	confans=confirm("Are you sure you want to generate a serial key?")
	if(confans)
	{    
		return true;
	}
	else
	{
		return false;
	}
}
function delete_field()
{
	var confans;
	confans=confirm("Are you sure you want to delete this field?")
	if(confans)
	{    
		return true;
	}
	else
	{
		return false;
	}
}
function KeyDownHandler(btn)    
{         
	if (event.keyCode == 13)           
	{            		
	event.returnValue    =    false;            
	event.cancel        =    true;         
	var obj = document.getElementById(btn);        
	obj.click();             
	}     
}

function confirmPublish()
{
	var confans;
	//confans=confirm('Once you publish "Product Template" you cannot edit the same. Are you sure, you want to publish this template?')
	confans=confirm('Are you sure you want to publish this Product Template? Re-Check the Product Template to make sure everything is in the way you want it to be. Once published you can do only a limited editing of the Product Template.')	

	if(confans)
	{    
		return true;
	}
	else
	{
		return false;
	}
}

function alertMessage(vType)
{
	var Mess="";
	
	switch(vType)
	{
		case 1:
			Mess="In order to Add or Manage Products or Product Templates, you must first Add Categories in your account. Click on Add Category to add new categories in your account.";
			break;
		
		case 2:
			Mess="In order to Add or Manage Products, you must first create Product Templates in your account. Click on Create Product Template to Add Product templates in your account.";
			break;
		
		case 3:
			Mess="In order to View Catalogue, you must first create Products in your account. Click on Add New Product to Add Products in your account.";
			break;
			
		default:	
			Mess="";
	}
	
	alert(Mess);
}

function ActivateRec(vActive)
{
	var confans;

	if(vActive==0)
	{		
		confans=confirm("Are you sure you want to Activate this job?")
	}
	else if(vActive==1)
	{
		confans=confirm("Are you sure you want to De-Activate this job?")
	}
	
	if(confans)
	{    
		return true;
	}
	else
	{
		return false;
	}
}

function KeyDownHandler(btn)    
{         
	if (event.keyCode == 13)           
		{            		
		event.returnValue	=	false;            
		event.cancel		=	true;         
		var obj = document.getElementById(btn);        
		obj.click();             
		}     
}

var hidden_before_length=0
function textCounter1(vMaxsize,vKeyType,vObjName,vDisplayNO)
{
	vDisplayNO.value=(vObjName.value.length);
	
		if (vDisplayNO.value>vMaxsize)
		{
			if (vKeyType==0 || vKeyType==3)
			{
				if (hidden_before_length==0 || (hidden_before_length==1 && vKeyType==3 ))
				{
					alert("You cannot add more than " + vMaxsize + " characters in the this field.");
					vObjName.focus();
					hidden_before_length=1
					return false;
				}
			}
		}
	return true;
}		

function email_check(vObjName)
{	
	var temp_email=vObjName.value
	var temp_email_split=temp_email.split("@")

	if(temp_email_split.length!=2)
	{
		alert("Email address is incorrect.")
		vObjName.focus()
		return false;
	}
	if(temp_email_split[temp_email_split.length-1].length<=1)
	{
		alert("Email address is incorrect.")
		vObjName.focus()
		return false;
	}
	var temp_split_comma=temp_email_split[temp_email_split.length-1].split(".")
	if(temp_split_comma.length<=1)
	{
		alert("Email address is incorrect.")
		vObjName.focus()
		return false;
	}
	if (temp_split_comma[temp_split_comma.length-1].length<=1)
	{
		alert("Email address is incorrect.")
		vObjName.focus()
		return false;
	}
	else
	{
		if(!isNaN(temp_split_comma[1]))
		{
			alert("Email address is incorrect.")
			vObjName.focus()
			return false;
		}
	}
	return true;
}

function fileMore_validation(vObj,strMess)
{	
	mFileName= vObj;
	
	mFileName = eval(mFileName);
	filename = mFileName.value;
	
	totalChars = mFileName.value.length;
	indexofdot = filename.lastIndexOf(".",totalChars)
	fileExt = filename.substring(totalChars,indexofdot)
	
	
	if(fileExt.toUpperCase() != ".JPG" && fileExt.toUpperCase() != ".GIF")
		{ 	
			return strMess;
		}
	
	return "";
}

function fileMore_validation_global(vObj,strMess,strExt)
{	
	mFileName= vObj;
	
	mFileName = eval(mFileName);
	filename = mFileName.value;
	
	totalChars = mFileName.value.length;
	indexofdot = filename.lastIndexOf(".",totalChars)
	fileExt = filename.substring(totalChars,indexofdot)
	
	
	if(fileExt.toUpperCase() != strExt && fileExt.toUpperCase() != strExt)
		{ 	
			return strMess;
		}
	
	return "";
}

function email_check(vObjName,strMess)
{	
	var temp_email=vObjName.value
	var temp_email_split=temp_email.split("@")

	if(temp_email_split.length!=2)
	{
		return strMess;
	}
	if(temp_email_split[temp_email_split.length-1].length<=1)
	{
		return strMess;
	}
	var temp_split_comma=temp_email_split[temp_email_split.length-1].split(".")
	if(temp_split_comma.length<=1)
	{
		return strMess;
	}
	if (temp_split_comma[temp_split_comma.length-1].length<=1)
	{
		return strMess;
	}
	else
	{
		if(!isNaN(temp_split_comma[1]))
		{
			return strMess;
		}
	}
	return '';
}
function email_check_multiple(vObjName,strMess)
{	
	var temp_email=vObjName.value;
	var temp_email_temp=temp_email.split(",");

	for(var i=0;i<temp_email_temp.length;i++)
	{
		var temp_email_split=temp_email_temp[i].split("@")

		if(temp_email_split.length!=2)
		{
			return strMess;
		}
		if(temp_email_split[temp_email_split.length-1].length<=1)
		{
			return strMess;
		}
		var temp_split_comma=temp_email_split[temp_email_split.length-1].split(".")
		if(temp_split_comma.length<=1)
		{
			return strMess;
		}
		if (temp_split_comma[temp_split_comma.length-1].length<=1)
		{
			return strMess;
		}
		else
		{
			if(!isNaN(temp_split_comma[1]))
			{
				return strMess;
				break;
			}
		}
	}
	
	return '';
}
function Trim(s) 
{
  // Remove leading spaces and carriage returns
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}	  
function validate_date(dd,mm,yy)	  
{	
	if((dd=="") || (mm=="") || (yy==""))
	{
	return "* Invalid Date"
	}	
	if((mm==4)||(mm==6)||(mm==9)||(mm==11))
	{
		if(dd>30)
		{
		//alert("Invalid date")
		return "* Invalid date"
		}
	}
	else if(mm==2)
	{
		if(yy%4!=0)
		{
			if(dd>28)
			{
			//alert("Invalid date")
			return "* Invalid date"
			}
		}
		else
		{
		if(dd>29)
			{
			//alert("Invalid date")
			return "* Invalid date"
			}
		}
	}
	return ""
}

function validate_date(dd,mm,yy,strMess)	  
{	
	if((dd=="") || (mm=="") || (yy==""))
	{
	return strMess
	}	
	if((mm==4)||(mm==6)||(mm==9)||(mm==11))
	{
		if(dd>30)
		{
		//alert("Invalid date")
		return strMess
		}
	}
	else if(mm==2)
	{
		if(yy%4!=0)
		{
			if(dd>28)
			{
			//alert("Invalid date")
			return strMess
			}
		}
		else
		{
		if(dd>29)
			{
			//alert("Invalid date")
			return strMess
			}
		}
	}
	return ""
}

function validate_special_char(vObjName,str_disp)
{
var s
s=""
	var iChars = "!@#$%^ &*()+=-[]\\\';,./{}|\":<>?"
	for (var i = 0; i < vObjName.length; i++) 
	{
	  if (iChars.indexOf(vObjName.charAt(i)) != -1)
	   {
		s="* " + str_disp + " may consist of a-z, 0-9 & underscore \n"
	
		break;
		}
	}
return s;	
}
//DHTML Window script- Copyright Dynamic Drive (http://www.dynamicdrive.com)
//For full source code, documentation, and terms of usage,
//Visit http://www.dynamicdrive.com/dynamicindex9/dhtmlwindow.htm

var dragapproved=false
var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function iecompattest(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function drag_drop(e){
if (ie5&&dragapproved&&event.button==1){
document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx+"px"
document.getElementById("dwindow").style.top=tempy+event.clientY-offsety+"px"
}
else if (ns6&&dragapproved){
document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx+"px"
document.getElementById("dwindow").style.top=tempy+e.clientY-offsety+"px"
}
}

function initializedrag(e){
offsetx=ie5? event.clientX : e.clientX
offsety=ie5? event.clientY : e.clientY
document.getElementById("dwindowcontent").style.display="none" //extra
tempx=parseInt(document.getElementById("dwindow").style.left)
tempy=parseInt(document.getElementById("dwindow").style.top)

dragapproved=true
document.getElementById("dwindow").onmousemove=drag_drop
}

function loadwindow(url,width,height){
if (!ie5&&!ns6)
window.open(url,"","width=width,height=height,scrollbars=1")
else{
document.getElementById("dwindow").style.display=''
document.getElementById("dwindow").style.width=initialwidth=width+"px"
document.getElementById("dwindow").style.height=initialheight=height+"px"
document.getElementById("dwindow").style.left="140px"
document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+90+"px" : iecompattest().scrollTop*1+90+"px"
document.getElementById("cframe").src=url
}
}

function maximize(){
if (minrestore==0){
minrestore=1 //maximize window
document.getElementById("maxname").setAttribute("src","images/ico/restore.gif")
document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : iecompattest().clientWidth+"px"
document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : iecompattest().clientHeight+"px"
document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px"
document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px"
}
else{
minrestore=0 //restore window
document.getElementById("maxname").setAttribute("src","images/ico/max.gif")
document.getElementById("dwindow").style.width=initialwidth
document.getElementById("dwindow").style.height=initialheight
document.getElementById("dwindow").style.left=ns6? window.pageXOffset*1+90+"px" : iecompattest().scrollLeft*1+90+"px"
document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+90+"px" : iecompattest().scrollTop*1+90+"px"
}

}

function closeit(){
document.getElementById("dwindow").style.display="none"
if(document.getElementById("refreshPage").value==1)
{
	window.location.reload();
}
}

function stopdrag(){
dragapproved=false;
document.getElementById("dwindow").onmousemove=null;
document.getElementById("dwindowcontent").style.display="" 
}

function GenerateChoices(NoChoice)
{	
	Edit=0
	document.getElementById('divChoice').innerHTML = GenerateHTML(NoChoice,Edit);	
	SetChoices(NoChoice,document.getElementById("ctl00_Middle_hidChoiceName").value);
}

function GenerateChoicesEdit(NoChoice)
{	
	Edit=1
	document.getElementById('divChoice').innerHTML = GenerateHTML(NoChoice,Edit);	
	SetChoices(NoChoice,document.getElementById("ctl00_Middle_hidChoiceName").value);
}

function GenerateHTML(NoChoice,Edit)
{
	var strReadonly="";
	var intNoChoice=GetNoChoices(document.getElementById("ctl00_Middle_hidChoiceName").value);
	var textBoxHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='2' class='black_content'>";
	
	for(i = 1 ; i <= NoChoice ; i++)
	{	
		elementId = 'txtChoiceName_'+i;		
		
		if((Edit==1) && (i<=intNoChoice))
			strReadonly = " disabled='disabled' ";
			
		textBoxHTML += "<tr>";
		textBoxHTML += "<td width='5%'><b>"+ i +".</b></td>";
		textBoxHTML += "<td><input type='text' name='" + elementId + "'"  + strReadonly + " class='tbox' maxlength='50'></td>";
		textBoxHTML += "</tr>";
		strReadonly="";
	}
	textBoxHTML += "</table>";

	return textBoxHTML;
}

function GetChoices(NoChoice)
{
	var strValues = "";
	var i;
	for(i = 1 ; i <= NoChoice ; i++)
	{	
		elementId = 'txtChoiceName_'+i;	
		if(strValues!=""){strValues=strValues+"~"}
		strValues+=document.getElementById(elementId).value;
	}	
	return strValues
}

function GetNoChoices(strChoice)
{
	splitStrChoice=strChoice.split("~");

	return splitStrChoice.length
}

function SetChoices(NoChoice,strChoice)
{
	var i,TempChoice;
	splitStrChoice=strChoice.split("~");

	for(i = 1 ; i <= NoChoice ; i++)
	{		
		elementId = 'txtChoiceName_'+i;	
		if(i<=splitStrChoice.length)		
		{
			TempChoice=splitStrChoice[i-1]
		}
		document.getElementById(elementId).value=TempChoice;
		TempChoice="";
	}	
}
function openHelpWindow(vPage)
{
	wind=open(vPage,'','width=600,height=300,left=150,top=150,scrollbars=1,resizable=yes');
	//loadwindow(vPage,600,450)
}
