
function getValue(elementId)
{	
	if (document.getElementById(elementId) != undefined)
	{
		return  document.getElementById(elementId).value;
	}else
	{
		return false;
	}
}

function setValue(elementId,value)
{	
	if (document.getElementById(elementId) != undefined)
	{
		document.getElementById(elementId).value=value;
	}else
	{
		return false;
	}
}


function setInnerHtml(elementId,value)
{	
	if (document.getElementById(elementId) != undefined)
	{
		document.getElementById(elementId).innerHTML=value;
	}else
	{
		return false;
	}
}

function ge(elementId)
{	
	if (document.getElementById(elementId) != undefined)
	{
		return  document.getElementById(elementId);
	}else
	{
		return false;
	}
}

function roundNumber(num, dec,display) {
	if (num == 0) {
		return 0;
	}
	var res = 0;
	res = num;
	try
	{
		res = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec)
		s = new String(res);		
		if(s.indexOf('.') < 0) { s += '.00';} //return parseFloat(s);
		if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
		if(display)
		{
			return s;
		}else
		
		{
			return parseFloat(s);
		}
	}catch(x) { return 0; }	
}


function load_partners(partner)
{
	new Ajax.Updater('aj_par','ajax/partners_list.php', {method: 'get', parameters: { partner: partner }, evalScripts: true, onComplete: function(){}});
}


function select_partner(partner)
{
	new Ajax.Updater('partner_select','ajax/select_partner.php', {method: 'get', parameters: { partner: partner }, evalScripts: true, onComplete: function(){}});
}

function checkformula()
{
	var name = getValue('name');
	var email = getValue('email');
	var phone = getValue('phone');
	
	var partner = getValue('partner_select');
	var partner_info=partner.split('!'); 
	
	partner = partner_info[0];
	partner_mail = partner_info[1];
	//alert(partner);
	//alert(partner_mail);
	var city = getValue('city');
	var questions = getValue('message');
	var color = getCurrentColor(); 
	var error = false;
		
	if (name.length<=0) { error = true; document.getElementById('name_label').style.color='red'; document.getElementById('name_label').style.fontWeight='bold'; } else { document.getElementById('name_label').style.color='#000000'; document.getElementById('name_label').style.fontWeight='normal'; }
	if (email.length<=0) { error = true;  document.getElementById('email_label').style.color='red'; document.getElementById('email_label').style.fontWeight='bold'; } else { document.getElementById('email_label').style.color='#000000'; document.getElementById('email_label').style.fontWeight='normal'; }
	if (phone.length<=0) { error = true;  document.getElementById('phone_label').style.color='red'; document.getElementById('phone_label').style.fontWeight='bold'; } else { document.getElementById('phone_label').style.color='#000000'; document.getElementById('phone_label').style.fontWeight='normal'; }
	if (partner=='x') { error = true;  document.getElementById('partner_label').style.color='red'; document.getElementById('partner_label').style.fontWeight='bold'; } else { document.getElementById('partner_label').style.color='#000000'; document.getElementById('partner_label').style.fontWeight='normal'; }
	
	if(!error) 
	{ 
		document.getElementById('form_wrapper').style.display='none'; document.getElementById('ok_sended').style.display='block';  
		new Ajax.Updater('tracklist','ajax/submit_order.php', {method: 'post', parameters: { name: name,email: email,phone: phone, partner: partner, city: city, questions: questions, color: color,partner_mail: partner_mail }, onSuccess: function(transport) {}});

	}
}

function getCurrentColor()
{
	var c1 = ge('c1');
	var c2 = ge('c2');
	var c3 = ge('c3');
	var c4 = ge('c4');
	
	if(c1.checked) { return 'Black Matte'; }
	if(c2.checked) { return 'Passion Purple'; }
	if(c3.checked) { return 'Cherry Red'; }
	if(c4.checked) { return 'Flamingo Pink'; } 
}
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


window.onload = function() { load_partners(0); };


/*
var press = true;
var total = 0;
var order = new Array();
var model  = new Array("m171","m173","mfliptip","m170","m138","m176");
var prices = new Array(9.9,9.9,9.9,6,5.9,15.2);
var x;
var total = 0;
var order_array ='';

function takeaction() {

// DOUBLE CLICK PREVENT
	if (!press) {
		return false;
	}
	else {
		press = false;
	}
	
// CHECK TOTAL
	if (total == 0) {
		text2error('total_price');
		text2error('total_price_text');
		press = true;
		return false;
	}
	else {
		text2normal('total_price');
		text2normal('total_price_text');
		var totalsum = total;
	}

// CHECK NAME
	if ($('name').value.blank()) {
		input2error('name');
		$('name').focus();
		press = true;
		return false;
	}
	else {
		input2normal('name');
		var name = $('name').value;
	}

// CHECK PHONE
	if ($('phone').value.blank()) {
		input2error('phone');
		$('phone').focus();
		press = true;
		return false;
	}
	else {
		input2normal('phone');
		var phone = $('phone').value;
	}

// CHECK EMAIL
	if ($('email').value.blank()) {
		input2error('email');
		$('email').focus();
		press = true;
		return false;
	}
	else {
		input2normal('email');
		var email = $('email').value;
	}

// CHECK CITY
	if ($('city').value.blank()) {
		input2error('city');
		$('city').focus();
		press = true;
		return false;
	}
	else {
		input2normal('city');
		var city = $('city').value;
	}

// CHECK ZIP
	if ($('zip').value.blank()) {
		input2error('zip');
		$('zip').focus();
		press = true;
		return false;
	}
	else {
		input2normal('zip');
		var zip = $('zip').value;
	}

// CHECK ADDRESS
	if ($('address').value.blank()) {
		input2error('address');
		$('address').focus();
		press = true;
		return false;
	}
	else {
		input2normal('address');
		var address = $('address').value;
	}
	
// AJAX
	var url = './submitorder.php';
	var pars = {'name' : name, 'phone' : phone, 'email' : email, 'city' : city, 'zip' : zip, 'address' : address,'total' : totalsum,'order_array' : order_array};
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: pars, 
			onComplete: function(transport) {

			// HIDE FORM
				$('order_table').style.display = 'none';
				$('form_table').style.display = 'none';
				$('order_btn_shell').style.display = 'none';
				$('orderstatus').style.display = 'inline';
				$('tracker').insert(transport.responseText);
				press = true;
			
			}
		}
	);
}

function boost_q(modelid)
{
	total = 0;
	order = new Array();

	var max = 5;
	var el = ge('qty'+modelid);
	var x;
	var q=0;
	var tmp=0;
	var model_price=0;
	order_array='';
	
	try { el.selectedIndex = el.selectedIndex+1; } catch (err) { }
		
	for (x in model)
  	{
	   if(q = getValue('qty'+model[x]) && model[x])
	   { 	  
	   	el = ge('qty'+model[x]); 
 	   	total = roundNumber(total + (el.selectedIndex*prices[x]),2,false);
 	   	total_display = roundNumber(total,2,true);
 	   	model_price = roundNumber(el.selectedIndex*prices[x],2,true);
 	   	setInnerHtml('total_price_'+model[x],model_price+' лв.');

 	   	if(el.selectedIndex>0)
 	   	{
 	   		if(el.selectedIndex==1) { tmp = ' брой - '; } else { tmp = ' броя - '; }
			order_array += model[x]+'='+el.selectedIndex+',';
 	   	}
	   }//if
  	}//for
  	setInnerHtml('total_price',total_display+' лв.');
  

// CLEAR ERROR
	if (total > 0) {
		text2normal('total_price');
		text2normal('total_price_text');
	}

}//boost_q


function input2normal(id) {
	$(id).style.borderColor = '#83715C';
	$(id).style.backgroundColor = '#FFFFFF';
}

function input2active(id) {
	$(id).style.borderColor = '#FEC211';
}

function input2error(id) {
	$(id).style.backgroundColor = '#FFF3CF';
	$(id).focus();
}

function text2error(id) {
	$(id).style.color = '#C70E0E';
}

function text2normal(id) {
	$(id).style.color = '#453A33';
}

function statushide(status) {
	$(status).style.display = 'none';

}

function statusshow(status) {
	$(status).style.display = 'inline';
	statushide.delay(5,status)
}

function getValue(elementId)
{	
	if (document.getElementById(elementId) != undefined)
	{
		return  document.getElementById(elementId).value;
	}else
	{
		return false;
	}
}

function setValue(elementId,value)
{	
	if (document.getElementById(elementId) != undefined)
	{
		document.getElementById(elementId).value=value;
	}else
	{
		return false;
	}
}


function setInnerHtml(elementId,value)
{	
	if (document.getElementById(elementId) != undefined)
	{
		document.getElementById(elementId).innerHTML=value;
	}else
	{
		return false;
	}
}

function ge(elementId)
{	
	if (document.getElementById(elementId) != undefined)
	{
		return  document.getElementById(elementId);
	}else
	{
		return false;
	}
}

function roundNumber(num, dec,display) {
	if (num == 0) {
		return 0;
	}
	var res = 0;
	res = num;
	try
	{
		res = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec)
		s = new String(res);		
		if(s.indexOf('.') < 0) { s += '.00';} //return parseFloat(s);
		if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
		if(display)
		{
			return s;
		}else
		
		{
			return parseFloat(s);
		}
	}catch(x) { return 0; }	
}

window.onload = function() {
	boost_q(false);
};
*/