var focusimage = 1;
var ShipAndBillMsg,msgB,msgS;
var TypePost = new Array(0,0);
function changeimg(obj,i){
	obj.src = obj.src.replace("vsimg55.php","vsimg.php");
	document.products.frontimg.src=obj.src.replace("vsimg.php","simg.php");
	focusimage = i;
}
function maxsizeimg(obj,i){
	addadress = "&i="+focusimage;
	window.open("/slideimg.php?product="+obj+addadress,"","menubar=no,scrollbars=no,status=no,width=530,height=600");
	return false;
}
function scryti(ARR,obj){
if(obj.value=='Close')obj.value='Show';
else obj.value='Close';
	for(el in ARR){
		str =  ARR[el];
		str2=document.getElementById(str+'');
//		str2=document.str1;
		if(str2.style.display==''){
			str2.style.display='none';
		}else{
			str2.style.display='';
		}
	}
}
function open1(ARR){
	for(el in ARR){
		str =  ARR[el];
		str2=document.getElementById(str+'');
		str2.style.display='';
	}
}
function close1(ARR){
	for(el in ARR){
		str =  ARR[el];
		str2=document.getElementById(str+'');
		str2.style.display='none';
	}
}
function init(){
	close1(['tr2','tr3','tr4']);open1(['tr1']);
}
function CheckEmail(form) {
	var rejectedDomain=new Array()
	var index=0;
	rejectedDomain[index++]="zdnetmail"
	var rejected=false
	var testresults=true
	var str=form
	var filter=/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i
	if (filter.test(str)){
		var tempstring = str.split("@")
		tempstring = tempstring[1].split(".")
		for (i=0; i<rejectedDomain.length; i++) {
			if (tempstring[0]==rejectedDomain[i])
			rejected=true
		}
		if (rejected) {
			var message="Please input a more official email address!\n"
			message += "The following addresses are not allowed:\n"
			for (i=0; i<rejectedDomain.length; i++) {
				message += "\t" + rejectedDomain[i] + "\n"
			}
		//	alert( message) ;
			testresults=false
		}
	} else {
		message="Please input a complete and valid email address!"
	//	alert( message)
		testresults=false
	}
	return (testresults)
}
function CheckSimple(value)
{  // alert(value);
	var str=value;
	if(str.length<2) {return false; }
	else
	return true;
}
function CheckPhone(value)
{  // alert(value);
	var str=value;
	var filter=/^[0-9 \-\(\)\+]{5,17}$/i
	if(filter.test(str)){
		return true;
	}else return false;
}
function CheckName(value){
	// alert(value);
	var str=value;
	var filter=/^[a-zA-Z0-9\. \-\(\)\+]{2,17}$/i
	if(filter.test(str)){
		return true;
	}else return false;
}
function CheckAddress(value){
	// alert(value);
	var str=value;
	var filter=/^.{2,}$/i
	if(filter.test(str)){
		return true;
	}else return false;
}
function IfCorrect(correct,field){
	//alert(correct);
	obj=document.getElementById(field+'');
	//alert(obj);
	if(correct==true){
		obj.className='check_true';
	}else{
		obj.className='check_false';
	}
	return false;
}
var ExtDisabled = new Array(10);
//ExtDisabled['NextPersonal'] = false;
//ExtDisabled['NextBilling'] = false;
function EnableNext(arr,button1,rtype){
 //alert(arr);
 button1=document.getElementById(button1+'');
 //button1.disabled=false;
 if(ExtDisabled[button1]==undefined){
 	ExtDisabled[button1] = false;
 }
 ExtDisabled[button1.id] = false;
 button1.title="";
 shipandbill = 0;
 for(el in arr){
	str =  arr[el];
	if(str=='BILLADDRESS'){
		shipandbill = 1;
	}
	str2=document.getElementById(str+'');
	if(str2.className=="check_false"){
	  //button1.disabled=true;
	  ExtDisabled[button1.id] = true;
	  button1.title="Please check fields marked with orange";
	  msg = "Please check fields marked with orange";
	  if(shipandbill == 1){
	  	msg += '\n\n'+ShipAndBillMsg;
	  }
	  if(rtype==1){
	  	return false;
	  }else{
	  	alert(msg);
	  	break;
	  }
	}
 }
 return true;
}

function test_button_NextPersonal(t){
	EnableNext(['EMAIL','FNAME','LNAME','PHONE'],'NextPersonal',0);
	if(t==1) return false;
	if(ExtDisabled['NextPersonal']){
		return false;
	}else{
		close1(['tr2','tr1','tr4']);open1(['tr3']);
		open_tab(2);
		return false;
	}
}

function test_button_NextBilling(t){
	test_copy();
	shippandbill();
	EnableNext(['BILLADDRESS','BILLCITY','BILLSTATE','BILLCOUNTRY','BILLZIP','SHIPADDRESS','SHIPCITY','SHIPSTATE','SHIPCOUNTRY','SHIPZIP'],'NextBilling',0);
	if(t==1) return false;
	if(ExtDisabled['NextBilling']){
		return false;
	}else{
		close1(['tr1','tr3','tr2']);
		open1(['tr4']);
		open_tab(3);
		return false;
	}
}

function copy(){
 document.getElementById('tBILLADDRESS').value = document.getElementById('tSHIPADDRESS').value;
 document.getElementById('tBILLCITY').value    = document.getElementById('tSHIPCITY').value;
 document.getElementById('tBILLCOUNTRY').value = document.getElementById('tSHIPCOUNTRY').value;
 country_change('BILL');
 document.getElementById('tBILLSTATE').value   = document.getElementById('tSHIPSTATE').value;
 document.getElementById('tBILLZIP').value     = document.getElementById('tSHIPZIP').value;
 j=CheckAddress(document.getElementById('tBILLADDRESS').value); IfCorrect(j,'BILLADDRESS');
 j=CheckName(document.getElementById('tBILLCITY').value); IfCorrect(j,'BILLCITY');
 CheckStateCountry('b');
 j=CheckName(document.getElementById('tBILLZIP').value); IfCorrect(j,'BILLZIP');
}

function shippandbill(){
	msgB = '';
	msgS = '';
	ShipAndBillMsg = '';

	BillState = document.getElementById('tBILLSTATE');
	BillCountry = document.getElementById('tBILLCOUNTRY');
	ShipState = document.getElementById('tSHIPSTATE');
	ShipCountry = document.getElementById('tSHIPCOUNTRY');
	ship = document.getElementById('samewithship_id');
	if(BillCountry.value != '' && BillState.value!=''){
		if(CityToShop[BillCountry.value]==undefined){
			if(BillState.value!='XX' && ship.checked==false){
				msgB += '  For '+BillCountry.options[BillCountry.selectedIndex].text+' you have to choose the state.\n';
			}
		}else if(CityToShop[BillCountry.value][BillState.value]==undefined){
			msgB += '  For '+BillCountry.options[BillCountry.selectedIndex].text+' you have to choose the state.\n';
		}
	}
	if(ShipCountry.value != '' && ShipState.value!=''){
		if(CityToShop[ShipCountry.value]==undefined){
			if(ShipState.value!='XX'){
				msgS += '  For '+ShipCountry.options[ShipCountry.selectedIndex].text+' you have to choose the state.\n';
			}
		}else if(CityToShop[ShipCountry.value][ShipState.value]==undefined){
			msgS += '  For '+ShipCountry.options[ShipCountry.selectedIndex].text+' you have to choose the state.\n';
		}
	}

	if(msgB != ''){
		ShipAndBillMsg += 'Bill Information:\n'+msgB;
	}
	if(msgS != ''){
		ShipAndBillMsg += 'Ship Information:\n'+msgS;
	}
/*	if(ShipAndBillMsg != ''){
		alert(ShipAndBillMsg);
		return false;
	} */
	return true;
	
}

function test_copy(){
	if(document.getElementById('samewithship_id').checked){
		copy();
	}
}

function CheckStateCountry(ltype){
	shippandbill();
	BillState = document.getElementById('tBILLSTATE');
	BillCountry = document.getElementById('tBILLCOUNTRY');
	ShipState = document.getElementById('tSHIPSTATE');
	ShipCountry = document.getElementById('tSHIPCOUNTRY');
	ship = document.getElementById('samewithship_id');
	if(ltype=='s'){
		if(msgS!='' || ShipCountry.value == '' || ShipState.value==''){
			IfCorrect(false,'SHIPSTATE');
			IfCorrect(false,'SHIPCOUNTRY');
		}else{
			IfCorrect(true,'SHIPSTATE');
			IfCorrect(true,'SHIPCOUNTRY');
		}
	}
	if(ltype=='b' || ship.checked==true){
		if(msgB!='' || BillCountry.value == '' || BillState.value==''){
			IfCorrect(false,'BILLSTATE');
			IfCorrect(false,'BILLCOUNTRY');
		}else{
			IfCorrect(true,'BILLSTATE');
			IfCorrect(true,'BILLCOUNTRY');
		}
	}
}

function set_postal(pref){
//	alert(pref);
	formax = 0;
	formax2 = 0;
	postsel = 0;
	prefback = '';
	if(pref=='us'){
		postsel = TypePost[0];
		prefback = 'int';
		formax = post_int;
		formax2 = post_us;
	}else if(pref=='int'){
		postsel = TypePost[1];
		prefback = 'us';
		formax = post_us;
		formax2 = post_int;
	}
	for(i=0;i<formax2;i++){
		if(document.getElementById(pref+'_'+i).checked){
			postsel = i;
		}
	}
	for(i=0;i<formax;i++){
		if(document.getElementById(prefback+'_'+i).checked){
			if(pref=='int'){
				TypePost[0] = i;
			}else if(pref=='us'){
				TypePost[1] = i;
			}
		}
	}
	document.getElementById(pref+'_'+postsel).checked=true;
/*	if(document.getElementById(pref+'_0').checked==true){
		alert('yes');
	}else alert('no');*/
}

function open_shipandbill(){
	if(EnableNext(['EMAIL','FNAME','LNAME','PHONE'],'NextPersonal',1)){
		close1(['tr2','tr1','tr4']);open1(['tr3']);
		open_tab(2);
	}else{
		alert('It is necessary to fill the \'Personal Data\'!');
	}
}
function open_postalservices(){
	op_msg = '';
	if(!EnableNext(['EMAIL','FNAME','LNAME','PHONE'],'NextPersonal',1)){
		op_msg += 'It is necessary to fill the \'Personal Data\'!\n';
	}
	if(!EnableNext(['BILLADDRESS','BILLCITY','BILLSTATE','BILLCOUNTRY','BILLZIP','SHIPADDRESS','SHIPCITY','SHIPSTATE','SHIPCOUNTRY','SHIPZIP'],'NextBilling',1)){
		op_msg += 'It is necessary to fill the \'Shipping and Billing\' details!';
	};	
	if(op_msg != ''){
		alert(op_msg);
	}else{
		close1(['tr1','tr3','tr2']);open1(['tr4']);
		open_tab(3);
	}
}

function go_update(){
	
}

function go_search(txt){
	document.getElementById('search_box').value=txt;
	document.getElementById('search_form').submit();
}
function open_tab(itab){
	for(i=0;i<4;i++){
		//img_src = document.getElementById('scm_img'+i).src;
		if(i!=itab){
			//document.getElementById('scm_img'+i).src = img_src.replace('sky_bul.png','green_bul.png');
			document.getElementById('scm_td'+i).className = 'cat_page_link_up';
		}else{
			//document.getElementById('scm_img'+i).src = img_src.replace('green_bul.png','sky_bul.png');
			document.getElementById('scm_td'+i).className = 'cat_page_link_up_2';
		}
	}
}
function openfaqtab(tnum){
	for(i=0;i<3;i++){
		if(tnum==i){
			document.getElementById('tab'+i).className = 'faq_tab'+i+'_select';
			document.getElementById('tab_txt'+i).style.display = '';
		}else{
			document.getElementById('tab'+i).className = 'faq_tab'+i+'';
			document.getElementById('tab_txt'+i).style.display = 'none';
		}
	}
}
function country_change(sobj){
	obj = document.getElementById('t'+sobj+'COUNTRY');
	obj2 = document.getElementById('t'+sobj+'STATE');
	obj2.options.length = 0;
	obj2.options[obj2.options.length] = new Option(" - Select the state - ", "");
	if(CityToShop[obj.value]!=undefined){
		for (var cabbr in CityToShop[obj.value]){
			obj2.options[obj2.options.length] = new Option(CityToShop[obj.value][cabbr], cabbr);
		}
	}else{
		obj2.options[obj2.options.length] = new Option(CityToShop['XX']['XX'], 'XX');
	}
}

/*blog*/
// Startup variables
var imageTag = false;
var theSelection = false;

// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;

var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);
var include_name = '';
var img_name = "";

// Helpline messages
php_code_help = "Include bloc of php code: [PHP_CODE]code[/PHP_CODE]";
b_help = "Bold text: <b>text</b>";
i_help = "Italic text: <i>text</i>";
u_help = "Underline text: <u>text</u>";
q_help = "Quote text: [quote]text[/quote]";
c_help = "Code display: [code]code[/code]";
l_help = "List: [list]text[/list]";
o_help = "Ordered list: [list=]text[/list]";
img_help = "Insert image: [img]http://image_url[/img]";
url_help = 'Insert URL: <a href="http://link">ankr</a>';
a_help = "Close all open bbCode tags";
s_help = "Font color: [color=red]text[/color]  Tip: you can also use color=#FF0000";
f_help = "Font size: [size=x-small]small text[/size]";

bbcode = new Array();
bbtags = new Array('','','','','[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[a href=""]','[/a]','[img ','/]');

b_img = new Array();
b_img[4] = new Array();
b_img[4][0] = "bb_b.png";
b_img[4][1] = "bb_b_sel.png";
b_img[6] = new Array();
b_img[6][0] = "bb_i.png";
b_img[6][1] = "bb_i_sel.png";
b_img[8] = new Array();
b_img[8][0] = "bb_u.png";
b_img[8][1] = "bb_u_sel.png";

function bbstyle_go(bbnumber,obj){
	bbstyle(bbnumber,obj);
	return false;
}

function bbstyle(bbnumber,obj) {
	var txtarea = document.form1.DESCRIPTION;
	donotinsert = false;
	theSelection = false;
	bblast = 0;

	if(bbnumber==2 || bbnumber==20){
		setCaretToEnd();
		with(document){
			if(obj.style.display=='none'){
				obj.style.display='';
				return false;
			}else{
				obj.style.display='none';
			}
		}
	}

	if(bbnumber==18){
		urlTag=false;
		for(t=0;t<bbcode.length;t++){
			if(bbcode[t]==19){
				urlTag=true;
				break;
			}
		}
		if(urlTag==false){
			urllink = prompt('Insert url adress:', 'http://');
			bbtags[18] = dftags[0]+urllink+dftags[1];
			urlTag=true;
		}else{
			urlTag=false;
		}
	}

	if(bbnumber==20){
		setCaretToEnd();
		if(imgTag==false){
			bbtags[20] = dftags[2]+img_name+dftags[3];
			vTag=true;
		}else{
			imgTag=false;
		}
	}

	if (bbnumber == -1) { // Close all open tags & default button names
		while (bbcode[0]) {
			butnumber = arraypop(bbcode) - 1;
			txtarea.value += bbtags[butnumber + 1];
			//buttext = eval('document.form1.addbbcode' + butnumber + '.value');
			//eval('document.form1.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
			$old_img = document.getElementById("addbbcode"+butnumber).src;
			document.getElementById("addbbcode"+butnumber).src = $old_img.replace(b_img[butnumber][1],b_img[butnumber][0]);
		}
		imageTag = false; // All tags are closed including image tags :D
		txtarea.focus();
		return false;
	}

	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection) {
			// Add tags around selection
			document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
			txtarea.focus();
			theSelection = '';
			return false;
		}
	}else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
		return false;
	}

	// Find last occurance of an open tag the same as the one just clicked
	for (i = 0; i < bbcode.length; i++) {
		if (bbcode[i] == bbnumber+1) {
			bblast = i;
			donotinsert = true;
		}
	}

	if (donotinsert) {		// Close all open tags up to the one just clicked & default button names
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1]/*+include_name*/;
				//buttext = eval('document.form1.addbbcode' + butnumber + '.value');
				//eval('document.form1.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
				$old_img = document.getElementById("addbbcode"+butnumber).src;
				document.getElementById("addbbcode"+butnumber).src = $old_img.replace(b_img[butnumber][1],b_img[butnumber][0]);
				imageTag = false;
			}
			txtarea.focus();
//			if(include_name!='') include_name = '';
			return false;
	} else { // Open tags

		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			txtarea.value += bbtags[15];
			lastValue = arraypop(bbcode) - 1;	// Remove the close image tag from the list
			document.form1.addbbcode14.value = "Img";	// Return button back to normal state
			imageTag = false;
		}

		// Open tag
		txtarea.value += bbtags[bbnumber];
		if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
		arraypush(bbcode,bbnumber+1);
		//eval('document.form1.addbbcode'+bbnumber+'.value += "*"');
		$old_img = document.getElementById("addbbcode"+bbnumber).src;
		document.getElementById("addbbcode"+bbnumber).src = $old_img.replace(b_img[bbnumber][0],b_img[bbnumber][1]);
		txtarea.focus();
		return false;
	}
	storeCaret(txtarea);
	return false;
}

function setCaretToEnd(){
	var control = document.form1.DESCRIPTION;
	if(control.createTextRange){
		var range = control.createTextRange();
		range.collapse(false);
		range.select();
	}else if(control.setSelectionRange){
		control.focus();
		var length = control.value.length;
		control.setSelectionRange(length, length);
	}
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}

// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}

function mozWrap(txtarea, open, close){
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}

// Shows the help messages in the helpline window
function helpline(help) {
	document.form1.helpbox.value = eval(help + "_help");
}

function quest_start_time(){
	setTimeout("quest_hide();",40000);
}
function quest_hide(){
	document.getElementById("q_layer0").style.display = 'none';
}

// Replacement for arrayname.length property
function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}
/*blog end*/
